﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Saxon.Api;

namespace WMM.Tapioca.Formula.Aspects
{
    /// <summary>
    /// An aspect of output fact.
    /// </summary>
    public class Aspect
    {
        internal XNamespace formula = "http://xbrl.org/2008/formula";

        private string source;

        /// <returns> The  @source attribute contain a QName that MUST be either the uncovered QName 
        /// or the QName of one of the formula's fact variables. 
        /// </returns>
        internal string Source
        {
            get { return source; }
            set { source = value; }
        }

        protected static string EvaluateXPathExpression(string expression)
        {
            // Create a Processor instance.
            Processor processor = new Processor();

            // Create the XPath expression.
            XPathCompiler compiler = processor.NewXPathCompiler();

            XPathSelector selector = compiler.Compile(expression).Load();

            string result = selector.EvaluateSingle().ToString();

            return result;
        }
    }
}
